package com.blacktry.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.blacktry.entity.enums.OprLogConst;
import com.blacktry.entity.model.*;
import com.blacktry.service.*;
import com.blacktry.utils.ApiResultHandler;
import com.blacktry.utils.log.OperLog;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.bind.DefaultValue;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 试卷管理表 前端控制器
 * </p>
 *
 * @author blackTry
 * @since 2021-08-10
 */
@RestController
@RequestMapping("/question")
@Api(value = "题目模块", tags = "题目管理接口")
public class QuestionController {
    @Autowired
    private PaperManageService paperManageService;

    @Autowired
    private JudgeQuestionService judgeQuestionService;

    @Autowired
    private MultiQuestionService multiQuestionService;

    @Autowired
    private FillQuestionService fillQuestionService;

    @Autowired
    private SubjectiveQuestionService subjectiveQuestionService;


    @OperLog(operModul = "选择题模块-删除指定",operType = OprLogConst.DELETE,operDesc = "删除指定")
    @ApiOperation("删除指定")
    @DeleteMapping("/delete/{id}")
    public ApiResult<Integer> delete(@PathVariable Integer id){
        return ApiResultHandler.buildApiResult(200,"成功",fillQuestionService.delete(id));
    }


    @OperLog(operModul = "选择题模块-批量删除",operType = OprLogConst.DELETE,operDesc = "批量删除")
    @ApiOperation("批量删除")
    @DeleteMapping("/deleteBatchIds")
    public ApiResult<Integer> deleteBatchIds(String[] ids){
        return ApiResultHandler.buildApiResult(200,"成功",fillQuestionService.deleteBatchIds(ids));
    }

    @OperLog(operModul = "选择题模块-添加/更新",operType = OprLogConst.UPDATE,operDesc = "添加/更新")
    @ApiOperation("添加/更新")
    @PostMapping("/updateOrInsert")
    public ApiResult<Integer> updateOrInsert(@RequestBody FillQuestion fillQuestion){
        return ApiResultHandler.buildApiResult(200,"成功",fillQuestionService.updateOrInsert(fillQuestion));
    }

    @OperLog(operModul = "选择题模块-根据id查询",operType = OprLogConst.SELECT,operDesc = "根据id查询")
    @ApiOperation("根据id查询")
    @GetMapping("/select/{id}")
    public ApiResult<FillQuestion> select(@PathVariable Integer id){
        return ApiResultHandler.buildApiResult(200,"插入成功",fillQuestionService.select(id));
    }

    @OperLog(operModul = "选择题模块-查看所有",operType = OprLogConst.SELECT,operDesc = "查看所有")
    @ApiOperation("查看所有")
    @GetMapping("/selectAll")
    public ApiResult<List<FillQuestion>> selectAll(){
        return ApiResultHandler.buildApiResult(200,"成功",fillQuestionService.selectAll());
    }

    @OperLog(operModul = "选择题模块-分页查看所有",operType = OprLogConst.SELECT,operDesc = "分页查看所有")
    @ApiOperation("分页查看所有")
    @PostMapping("/selectAll/{page}/{size}")
    public ApiResult<Page<FillQuestion>> findAll(@RequestBody FillQuestion fillQuestion, @DefaultValue("1") @PathVariable("page") Integer page, @DefaultValue("6") @PathVariable("size") Integer size){
        System.out.println("分页查询所有");
        Page<FillQuestion> fillQuestionPage = new Page<>(page,size);
        return ApiResultHandler.buildApiResult(200, "请求成功！", fillQuestionService.selectPage(fillQuestion,fillQuestionPage));
    }
}

